package com.healthcloud.controller;

import java.util.List;
import java.util.Map;

import com.healthcloud.annotation.SysLog;
import com.healthcloud.entity.MsgVo;
import com.healthcloud.utils.ApiRes;
import com.healthcloud.utils.PageParam;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.healthcloud.entity.TestprojectkindEntity;
import com.healthcloud.service.TestprojectkindService;
import springfox.documentation.annotations.ApiIgnore;


/**
 * 检测项目大类
smart仪器项目在109<=id<=130区间内
 *
 * @author yucl
 * @email yucailong1111@126.com
 * @date 2017-11-17 10:17:56
 */
@ApiIgnore
@Controller
@RequestMapping("testprojectkind")
public class TestprojectkindController {
	@Autowired
	private TestprojectkindService testprojectkindService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("testprojectkind:list")
	public String list(@RequestParam Map<String, Object> params){
		return "bus/testprojectkind/testprojectkindmgr";
	}

	@RequiresPermissions("testprojectkind:list")
	@RequestMapping(value = "/searchTestprojectkind")
	@ResponseBody
    public MsgVo  searchTestprojectkind(TestprojectkindEntity bean,Model model, @ModelAttribute("pageParam")PageParam pageParam){
        List<TestprojectkindEntity> list = testprojectkindService.queryList(bean, pageParam);
        int count = testprojectkindService.queryTotal(bean);
        return new MsgVo(list,count,count,pageParam.getsEcho());
    }

	/**
	 * 新增页
	 */
	@RequestMapping("/tosave")
	@RequiresPermissions("testprojectkind:save")
    public String toSave(Model model) {
        return "bus/testprojectkind/addOrUpdatetestprojectkind";
    }

	/**
	 * 保存
	 */
    @SysLog("保存Testprojectkind")
    @RequestMapping("/save")
    @ResponseBody
    public ApiRes save(TestprojectkindEntity entity) {
        entity.setIsDel(0);
        entity.setInstrumentType(1);
        testprojectkindService.save(entity);
        return ApiRes.SUCCESS;
    }

	/**
	 * 修改页
	 */
	@RequestMapping("/toupdate")
    @RequiresPermissions("testprojectkind:update")
    public String toUpdate(@Param("testKindCode") String testKindCode, Model model) {

        TestprojectkindEntity entity = testprojectkindService.queryObject(testKindCode);
        model.addAttribute("entity", entity);

        return "bus/testprojectkind/addOrUpdatetestprojectkind";
    }

    /**
     * 修改
     */
    @SysLog("修改Testprojectkind")
    @RequestMapping("/update")
    @ResponseBody
    public ApiRes update(TestprojectkindEntity entity) {
        testprojectkindService.update(entity);
        return ApiRes.SUCCESS;
    }

    /**
     * 删除
     */
    @SysLog("删除Testprojectkind")
    @RequestMapping("/delete")
    @RequiresPermissions("testprojectkind:delete")
    @ResponseBody
    public ApiRes delete(String[] testKindCodes) {
        testprojectkindService.deleteBatch(testKindCodes);
        return ApiRes.SUCCESS;
    }

    /**
     * 查询列表
     */
    @RequestMapping("/select")
    public  @ResponseBody
    ApiRes selectTestProjectKind(TestprojectkindEntity bean, @ModelAttribute("pageParam")PageParam pageParam){

        List<TestprojectkindEntity> list = testprojectkindService.queryList(bean, pageParam);
        for(TestprojectkindEntity testprojectkindEntity : list) {
            testprojectkindEntity.setId(testprojectkindEntity.getTestKindCode());
        }
        int total = testprojectkindService.queryTotal(bean);
        return new ApiRes(true,list,null,String.valueOf(total));
    }
}
